/**
 * File: FilterArcConnectionDistanceEstimate.java
 * Created by: mhaimel
 * Created on: Nov 19, 2010
 * CVS:  $Id: FilterArcConnectionDistanceEstimate.java 1.0 Nov 19, 2010 10:59:44 AM mhaimel Exp $
 */
package uk.ac.ebi.curtain.controller.graph;

import java.io.Serializable;
import java.util.List;

import uk.ac.ebi.curtain.controller.SingleSubmitController;
import uk.ac.ebi.curtain.model.graph.Graph;
import uk.ac.ebi.curtain.model.graph.curtain.ContigInfo;
import uk.ac.ebi.curtain.model.graph.curtain.CurtainGraph;
import uk.ac.ebi.curtain.model.graph.curtain.ReadWrapper;
import uk.ac.ebi.curtain.model.graph.curtain.filter.ArcConnectionDistanceEstimate;

/**
 * @author mhaimel
 *
 */
public class FilterArcConnectionDistanceEstimate extends SingleSubmitController<Serializable, Serializable> {

	@Override
	protected void singleSubmit(List<Serializable> inputList) {
		CurtainGraph curtainGraph = getContext().getGraph();
		Graph<ContigInfo, ReadWrapper> graph = curtainGraph.getGraph();
		Integer categories = curtainGraph.getCategories();
		// reindex before starting
		graph.reindexArcs();
		graph.buildArcsIndex();
		
		for(Integer cat = 0; cat < categories; ++cat){
			Integer min = getContext().getArguments().getMinPairCount(cat);
			if(null == min){
				min = getContext().getArguments().getMinPairCountDefault();
			}
			getLog().debug("Filter Connections for " + cat + ": minimum set to "+ min +" ... ");
			
			Integer ins = getContext().getArguments().getCategory2InsertLength().get(cat);
			Integer sd = getContext().getArguments().getCategory2InsertLengthSd().get(cat);
			graph.processArcs(new ArcConnectionDistanceEstimate(ins, sd, cat,min));
		}		
		graph.reindexArcs();
		graph.buildArcsIndex();
	}
	
	
	
	
}
